Skip to content

refactor(deploy): template-generate the three Postgres manifests - #21

Merged
Harikeshav-R merged 1 commit into
feat/policies-and-loadgenfrom
refactor/template-postgres-manifests
Sep 11, 2026
Merged

Harikeshav-R merged 1 commit into
feat/policies-and-loadgenfrom
refactor/template-postgres-manifests

Conversation

@rsanghvi21

Copy link
Copy Markdown
Collaborator

Build-Plan Step Implemented

  • Step: A1.5/A1.6 (refactor on already-completed manifests).

Checkpoint Execution & Output

$ uv run python deploy/generate_postgres_manifests.py --check
OK: deploy/system/*-postgres.yaml match the generator.

$ uv run pytest tests/unit/deploy/test_system_manifests.py -v
7 passed in 0.49s

$ uv run pytest tests/unit --ignore=tests/unit/services/test_edge_gateway.py -k "not test_run_loadgen_with_owned_client_and_zero_rps" --cov=understudy --cov-branch --cov-fail-under=100
191 passed, 1 deselected, 100.00% coverage

$ uv run ruff check . && uv run ruff format --check . && uv run mypy --strict src tests && uv run lint-imports && uv run python scripts/check_mocks.py
All green.

ADRs Relied On

  • ADR-004 (Python everywhere) -- justifies a plain Python generator script over
    adopting Helm/Kustomize/Jsonnet, which this repo has never used and which would
    need its own ADR.
  • ADR-009 (postgres instance placement: prod-postgres in ust-prod, twin/system-postgres
    in ust-system) -- unchanged, just now generated rather than hand-written.

Mock Registry Disclosures

  • None.

Documentation Updates

  • docs/02-architecture.md §2.10: notes that the three postgres manifests are
    generated (with --check wired into tests), and that INSTANCES in the generator
    script is the place to edit, not the YAML files directly.

Definition of Done

  • Implementation complete for the named build-plan step
  • Unit tests written; 100% line and branch coverage of the added lines
  • make check green
  • Checkpoint command run and output matches, OR marked unverified with a reason
  • Docs updated where this change made them untrue
  • No new # MOCKED: marker without a row in docs/MOCKS.md
  • Conventional commit(s), conventional branch, PR opened, never pushed to main

Context

A /code-review pass against PR #6 flagged the three postgres manifests
(deploy/system/{prod,twin,system}-postgres.yaml) as near-identical, independently
hand-maintained files with nothing preventing them from silently drifting apart. This
PR replaces hand-maintenance with a generator: deploy/generate_postgres_manifests.py
builds each manifest as a Python dict from one template function plus a small
per-instance parameter table (namespace, image, POSTGRES_DB, resources, host port,
and system-postgres's extra init-script ConfigMap), and dumps it with PyYAML. The
generator's own --check mode is a new test
(test_postgres_manifests_match_generator) that fails CI the moment a future edit to
one file isn't mirrored by regenerating the others.

The three committed files are unchanged in substance -- I ran the generator and
diffed its output against what was already committed before touching anything, and
found the only difference was YAML quoting style (value: "postgres" vs
value: postgres), confirming the generator's template faithfully reconstructs the
existing, reviewed manifests rather than silently changing deployed configuration.

No Helm/Kustomize/Jsonnet is introduced (this repo has none today, and adopting one
would need a new ADR per AGENTS.md §2.1/§9) -- the generator is plain Python,
consistent with ADR-004 and the existing ${VAR} + str.replace convention used
elsewhere in deploy/policies/.

Base branch is feat/policies-and-loadgen (PR #6, still open), since deploy/system/
only exists on that branch's stack.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CzBeBUsZmE38K1kWeLMhNh

deploy/system/prod-postgres.yaml, twin-postgres.yaml, and
system-postgres.yaml were three independently hand-written,
near-identical Deployment+Service pairs (identical skeleton;
differing only in namespace, image, POSTGRES_DB, resources, host
port, and system-postgres's extra init-script ConfigMap/volume) with
nothing keeping them from drifting apart.

Add deploy/generate_postgres_manifests.py: a plain Python script
(fits ADR-004 "Python everywhere" -- this repo has no
Helm/Kustomize/Jsonnet anywhere, and adopting one would need a new
ADR, out of scope here) that builds each manifest as a dict from a
shared template function plus a small per-instance parameter table,
and dumps it with PyYAML. --check renders in-memory and diffs
(structurally, not byte-for-byte, since PyYAML formatting need not
match hand-written style) against the committed files, exiting
non-zero on drift; wired into
tests/unit/deploy/test_system_manifests.py so drift fails CI.

The three committed files are now generator output (regenerated via
this script) rather than hand-maintained; the only textual diff from
the prior hand-written versions is cosmetic YAML quoting. Documents
the generator in docs/02-architecture.md §2.10.

Implements build-plan step A1.5/A1.6 (refactor on already-completed
manifests).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CzBeBUsZmE38K1kWeLMhNh
@Harikeshav-R
Harikeshav-R merged commit d11f875 into feat/policies-and-loadgen Sep 11, 2026
1 check passed
@Harikeshav-R
Harikeshav-R deleted the refactor/template-postgres-manifests branch September 11, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants